﻿<ResourceDictionary
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero">
	<ControlTemplate x:Key="DataGridControlTemplate" TargetType="{x:Type DataGrid}">
		<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="True">
			<ScrollViewer x:Name="DG_ScrollViewer" Focusable="False" Style="{DynamicResource ScrollViewerStyle}" Template="{DynamicResource DataGridScrollViewerControlTemplate}">
				<ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
			</ScrollViewer>
		</Border>
	</ControlTemplate>
	<Style x:Key="DataGridColumnHeaderStyle" TargetType="{x:Type DataGridColumnHeader}">
		<Setter Property="VerticalContentAlignment" Value="Center"/>
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
					<Grid>
						<Themes:DataGridHeaderBorder BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" IsClickable="{TemplateBinding CanUserSort}" IsPressed="{TemplateBinding IsPressed}" IsHovered="{TemplateBinding IsMouseOver}" Padding="{TemplateBinding Padding}" SortDirection="{TemplateBinding SortDirection}" SeparatorBrush="{TemplateBinding SeparatorBrush}" SeparatorVisibility="{TemplateBinding SeparatorVisibility}">
							<ContentPresenter ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
						</Themes:DataGridHeaderBorder>
						<Thumb x:Name="PART_LeftHeaderGripper" HorizontalAlignment="Left">
							<Thumb.Style>
								<Style TargetType="{x:Type Thumb}">
									<Setter Property="Width" Value="8"/>
									<Setter Property="Background" Value="Transparent"/>
									<Setter Property="Cursor" Value="SizeWE"/>
									<Setter Property="Template">
										<Setter.Value>
											<ControlTemplate TargetType="{x:Type Thumb}">
												<Border Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}"/>
											</ControlTemplate>
										</Setter.Value>
									</Setter>
								</Style>
							</Thumb.Style>
						</Thumb>
						<Thumb x:Name="PART_RightHeaderGripper" HorizontalAlignment="Right">
							<Thumb.Style>
								<Style TargetType="{x:Type Thumb}">
									<Setter Property="Width" Value="8"/>
									<Setter Property="Background" Value="Transparent"/>
									<Setter Property="Cursor" Value="SizeWE"/>
									<Setter Property="Template">
										<Setter.Value>
											<ControlTemplate TargetType="{x:Type Thumb}">
												<Border Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}"/>
											</ControlTemplate>
										</Setter.Value>
									</Setter>
								</Style>
							</Thumb.Style>
						</Thumb>
					</Grid>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
		<Setter Property="Background" Value="{DynamicResource DataGridColumnHeaderBrush}"/>
		<Setter Property="MinHeight" Value="25"/>
		<Setter Property="Foreground" Value="{DynamicResource ButtonForeground}"/>
		<Setter Property="Padding" Value="5,0"/>
		<Setter Property="BorderBrush" Value="{DynamicResource ButtonInnerBrush}"/>
		<Setter Property="BorderThickness" Value="0,0,1,0"/>
		<Setter Property="SeparatorBrush" Value="Black"/>
		<Style.Triggers>
			<Trigger Property="IsMouseOver" Value="True">
				<Setter Property="Background" Value="{DynamicResource ButtonNormalBackground}"/>
			</Trigger>
			<Trigger Property="IsPressed" Value="True">
				<Setter Property="Background" Value="{DynamicResource ButtonCheckedBrush}"/>
			</Trigger>
		</Style.Triggers>
	</Style>
	
	<Style TargetType="{x:Type DataGrid}" x:Key="DataGridStyle">
		<Setter Property="HeadersVisibility" Value="Column"/>
		<Setter Property="Template" Value="{DynamicResource DataGridControlTemplate}"/>
		<Setter Property="ColumnHeaderStyle" Value="{DynamicResource DataGridColumnHeaderStyle}"/>
		<Setter Property="Background" Value="{DynamicResource ButtonDefaultStateBackground}"/>
		
	</Style>
	<ControlTemplate x:Key="DataGridScrollViewerControlTemplate" TargetType="{x:Type ScrollViewer}">
		<Grid>
			<Grid.ColumnDefinitions>
				<ColumnDefinition Width="Auto"/>
				<ColumnDefinition Width="*"/>
				<ColumnDefinition Width="Auto"/>
			</Grid.ColumnDefinitions>
			<Grid.RowDefinitions>
				<RowDefinition Height="Auto"/>
				<RowDefinition Height="*"/>
				<RowDefinition Height="Auto"/>
			</Grid.RowDefinitions>
			<Button Command="ApplicationCommands.SelectAll" Focusable="False" Style="{DynamicResource {ComponentResourceKey ResourceId=DataGridSelectAllButtonStyle, TypeInTargetAssembly={x:Type DataGrid}}}" Width="{Binding CellsPanelHorizontalOffset, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type DataGrid}}}">
				<Button.Visibility>
					<Binding Path="HeadersVisibility" RelativeSource="{RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type DataGrid}}">
						<Binding.ConverterParameter>
							<DataGridHeadersVisibility>All</DataGridHeadersVisibility>
						</Binding.ConverterParameter>
					</Binding>
				</Button.Visibility>
			</Button>
			<DataGridColumnHeadersPresenter x:Name="PART_ColumnHeadersPresenter" Grid.Column="1">
				<DataGridColumnHeadersPresenter.Visibility>
					<Binding Path="HeadersVisibility" RelativeSource="{RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type DataGrid}}">
						<Binding.ConverterParameter>
							<DataGridHeadersVisibility>Column</DataGridHeadersVisibility>
						</Binding.ConverterParameter>
					</Binding>
				</DataGridColumnHeadersPresenter.Visibility>
			</DataGridColumnHeadersPresenter>
			<ScrollContentPresenter x:Name="PART_ScrollContentPresenter" CanContentScroll="{TemplateBinding CanContentScroll}" CanHorizontallyScroll="False" Grid.ColumnSpan="2" CanVerticallyScroll="False" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" Grid.Row="1"/>
			<ScrollBar x:Name="PART_VerticalScrollBar" Grid.Column="2" Maximum="{TemplateBinding ScrollableHeight}" Orientation="Vertical" Grid.Row="1" Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}" Value="{Binding VerticalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" ViewportSize="{TemplateBinding ViewportHeight}" Style="{DynamicResource VerticalScrollBarStyle}"/>
			<Grid Grid.Column="1" Grid.Row="2">
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="{Binding NonFrozenColumnsViewportHorizontalOffset, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type DataGrid}}}"/>
					<ColumnDefinition Width="*"/>
				</Grid.ColumnDefinitions>
				<ScrollBar x:Name="PART_HorizontalScrollBar" Grid.Column="1" Maximum="{TemplateBinding ScrollableWidth}" Orientation="Horizontal" Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}" Value="{Binding HorizontalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" ViewportSize="{TemplateBinding ViewportWidth}" Style="{DynamicResource HorizontalScrollBarStyle}"/>
			</Grid>
		</Grid>
	</ControlTemplate>
</ResourceDictionary>